﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SlamCms.Common
{
	public enum CharacterType
	{
		Uppercase,
		Lowercase,
		Symbol,
		Number,
	}

	public static class RandomHelpers
	{
		private static readonly Random random = new Random();

		public static string Generate(int size, params CharacterType[] characterTypes)
		{
			lock (random)
			{
				List<CharacterType> availableTypes = characterTypes.ToList();
				string availableSymbols = "!$#@{}()";

				var sb = new StringBuilder();

				for (var i = 0; i < size; i++)
				{
					int index = random.Next(0, availableTypes.Count);
					var type = availableTypes[index];
					switch (type)
					{
						case CharacterType.Lowercase:
							sb.Append((char)random.Next('a', 'z' + 1));
							break;
						case CharacterType.Uppercase:
							sb.Append((char)random.Next('A', 'Z' + 1));
							break;
						case CharacterType.Number:
							sb.Append((char)random.Next('0', '9' + 1));
							break;
						case CharacterType.Symbol:
							sb.Append(availableSymbols[random.Next(0, availableSymbols.Length)]);
							break;
					}
				}

				return sb.ToString();
			}
		}
	}
}
